package com.menggudf.service.impl;

import com.menggudf.entity.Members;
import com.menggudf.mapper.MembersDao;
import com.menggudf.service.MembersService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (Members)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:30
 */
@Service("membersService")
public class MembersServiceImpl implements MembersService {
    @Resource
    private MembersDao membersDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Members queryById(Integer id) {
        return this.membersDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param members 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Members> queryByPage(Members members, PageRequest pageRequest) {
        long total = this.membersDao.count(members);
        return new PageImpl<>(this.membersDao.queryAllByLimit(members, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param members 实例对象
     * @return 实例对象
     */
    @Override
    public Members insert(Members members) {
        this.membersDao.insert(members);
        return members;
    }

    /**
     * 修改数据
     *
     * @param members 实例对象
     * @return 实例对象
     */
    @Override
    public Members update(Members members) {
        this.membersDao.update(members);
        return this.queryById(members.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.membersDao.deleteById(id) > 0;
    }
}
